from flask import Flask, redirect, jsonify, make_response, render_template

# 初始化 Flask 项目的服务
app = Flask(__name__)


@app.route('/')
def hello_world():  # put application's code here
	return 'Hello World!'


@app.route('/demo1')
def demo1():
	return redirect('https://www.baidu.com')


@app.route('/demo2')
def demo2():
	json_data = {
		'id': 11,
		'name': 'keke'
	}
	return jsonify(json_data)


@app.route('/demo3')
def demo3():
	# 自定义一个响应（元组），响应有三部分：response，status, headers
	return '自定义响应内容', 600, {'my_parm': 'python'}

@app.route('/demo4')
def demo4():
    resp = make_response('make response 响应内容')
    resp.status = 600
    resp.headers['my_parm'] = 'python'
    return resp


@app.route('/demo5')
def demo5():
    return render_template('index.html', name = 'keke', age = 18)

if __name__ == '__main__':
	app.run(host = '0.0.0.0', port = 8080, debug = True)
